home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / socketx / ECHO.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-10-06  |  11.7 KB  |  365 lines

  1. VERSION 5.00
  2. Object = "{C7212F93-30E8-11D2-B450-0020AFD69DE6}#1.0#0"; "SocketX.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   6945
  6.    ClientLeft      =   1095
  7.    ClientTop       =   1485
  8.    ClientWidth     =   7365
  9.    BeginProperty Font 
  10.       Name            =   "MS Sans Serif"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   700
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    ForeColor       =   &H80000008&
  19.    KeyPreview      =   -1  'True
  20.    LinkTopic       =   "Form1"
  21.    PaletteMode     =   1  'UseZOrder
  22.    ScaleHeight     =   6945
  23.    ScaleWidth      =   7365
  24.    Begin SocketXCtl.SocketXCtl SocketX 
  25.       Left            =   600
  26.       Top             =   6000
  27.       _cx             =   847
  28.       _cy             =   847
  29.       AcceptTimeout   =   0
  30.       BlockingMode    =   -842150451
  31.       Blocking        =   -1  'True
  32.       BroadcastEnabled=   -1  'True
  33.       ConnectTimeout  =   0
  34.       EventMask       =   63
  35.       KeepAliveEnabled=   0   'False
  36.       LibraryName     =   "WSOCK32.DLL"
  37.       LingerEnabled   =   0   'False
  38.       LingerMode      =   0
  39.       LingerTime      =   0
  40.       LocalAddress    =   ""
  41.       LocalPort       =   0
  42.       OutOfBandEnabled=   0   'False
  43.       ReceiveBufferSize=   8192
  44.       ReceiveTimeout  =   0
  45.       RemoteAddress   =   ""
  46.       RemoteName      =   ""
  47.       ReuseAddressEnabled=   0   'False
  48.       RemotePort      =   0
  49.       RouteEnabled    =   -1  'True
  50.       SendTimeout     =   8192
  51.       SendBufferSize  =   0
  52.       SocketType      =   0
  53.       TcpNoDelayEnabled=   0   'False
  54.    End
  55.    Begin VB.TextBox txtPort 
  56.       BeginProperty Font 
  57.          Name            =   "MS Sans Serif"
  58.          Size            =   8.25
  59.          Charset         =   0
  60.          Weight          =   400
  61.          Underline       =   0   'False
  62.          Italic          =   0   'False
  63.          Strikethrough   =   0   'False
  64.       EndProperty
  65.       Height          =   285
  66.       Left            =   4560
  67.       TabIndex        =   6
  68.       Text            =   "7"
  69.       Top             =   5520
  70.       Width           =   495
  71.    End
  72.    Begin VB.CheckBox chkLocalEcho 
  73.       Caption         =   "Local Echo"
  74.       BeginProperty Font 
  75.          Name            =   "MS Sans Serif"
  76.          Size            =   8.25
  77.          Charset         =   0
  78.          Weight          =   400
  79.          Underline       =   0   'False
  80.          Italic          =   0   'False
  81.          Strikethrough   =   0   'False
  82.       EndProperty
  83.       Height          =   255
  84.       Left            =   5280
  85.       TabIndex        =   4
  86.       Top             =   5520
  87.       Width           =   1215
  88.    End
  89.    Begin VB.CommandButton Command1 
  90.       Appearance      =   0  'Flat
  91.       BackColor       =   &H80000005&
  92.       Caption         =   "Connect"
  93.       BeginProperty Font 
  94.          Name            =   "MS Sans Serif"
  95.          Size            =   8.25
  96.          Charset         =   0
  97.          Weight          =   400
  98.          Underline       =   0   'False
  99.          Italic          =   0   'False
  100.          Strikethrough   =   0   'False
  101.       EndProperty
  102.       Height          =   375
  103.       Left            =   120
  104.       TabIndex        =   3
  105.       Top             =   5520
  106.       Width           =   1095
  107.    End
  108.    Begin VB.TextBox txtServer 
  109.       BeginProperty Font 
  110.          Name            =   "MS Sans Serif"
  111.          Size            =   8.25
  112.          Charset         =   0
  113.          Weight          =   400
  114.          Underline       =   0   'False
  115.          Italic          =   0   'False
  116.          Strikethrough   =   0   'False
  117.       EndProperty
  118.       Height          =   285
  119.       Left            =   2160
  120.       TabIndex        =   2
  121.       Text            =   "12.2.15.57"
  122.       Top             =   5520
  123.       Width           =   1695
  124.    End
  125.    Begin VB.TextBox txtTranscript 
  126.       BeginProperty Font 
  127.          Name            =   "Courier New"
  128.          Size            =   8.25
  129.          Charset         =   0
  130.          Weight          =   400
  131.          Underline       =   0   'False
  132.          Italic          =   0   'False
  133.          Strikethrough   =   0   'False
  134.       EndProperty
  135.       Height          =   5175
  136.       Left            =   120
  137.       MultiLine       =   -1  'True
  138.       ScrollBars      =   3  'Both
  139.       TabIndex        =   0
  140.       Top             =   120
  141.       Width           =   7095
  142.    End
  143.    Begin VB.Label Label4 
  144.       Caption         =   "If you are not connecting to a remote echo port (7) you should check the Local Echo box."
  145.       BeginProperty Font 
  146.          Name            =   "MS Sans Serif"
  147.          Size            =   8.25
  148.          Charset         =   0
  149.          Weight          =   400
  150.          Underline       =   0   'False
  151.          Italic          =   0   'False
  152.          Strikethrough   =   0   'False
  153.       EndProperty
  154.       Height          =   855
  155.       Left            =   5280
  156.       TabIndex        =   8
  157.       Top             =   5880
  158.       Width           =   2055
  159.    End
  160.    Begin VB.Label Label1 
  161.       Alignment       =   1  'Right Justify
  162.       Appearance      =   0  'Flat
  163.       BackColor       =   &H00C0C0C0&
  164.       Caption         =   "Port:"
  165.       BeginProperty Font 
  166.          Name            =   "MS Sans Serif"
  167.          Size            =   8.25
  168.          Charset         =   0
  169.          Weight          =   400
  170.          Underline       =   0   'False
  171.          Italic          =   0   'False
  172.          Strikethrough   =   0   'False
  173.       EndProperty
  174.       ForeColor       =   &H80000008&
  175.       Height          =   255
  176.       Left            =   4080
  177.       TabIndex        =   7
  178.       Top             =   5520
  179.       Width           =   375
  180.    End
  181.    Begin VB.Label Label3 
  182.       Caption         =   "Note: Not all servers you might choose support connections to all ports."
  183.       BeginProperty Font 
  184.          Name            =   "MS Sans Serif"
  185.          Size            =   8.25
  186.          Charset         =   0
  187.          Weight          =   400
  188.          Underline       =   0   'False
  189.          Italic          =   0   'False
  190.          Strikethrough   =   0   'False
  191.       EndProperty
  192.       Height          =   615
  193.       Left            =   2160
  194.       TabIndex        =   5
  195.       Top             =   6000
  196.       Width           =   2055
  197.    End
  198.    Begin VB.Label Label2 
  199.       Alignment       =   1  'Right Justify
  200.       Appearance      =   0  'Flat
  201.       BackColor       =   &H00C0C0C0&
  202.       Caption         =   "Server:"
  203.       BeginProperty Font 
  204.          Name            =   "MS Sans Serif"
  205.          Size            =   8.25
  206.          Charset         =   0
  207.          Weight          =   400
  208.          Underline       =   0   'False
  209.          Italic          =   0   'False
  210.          Strikethrough   =   0   'False
  211.       EndProperty
  212.       ForeColor       =   &H80000008&
  213.       Height          =   255
  214.       Left            =   1440
  215.       TabIndex        =   1
  216.       Top             =   5520
  217.       Width           =   615
  218.    End
  219. Attribute VB_Name = "Form1"
  220. Attribute VB_GlobalNameSpace = False
  221. Attribute VB_Creatable = False
  222. Attribute VB_PredeclaredId = True
  223. Attribute VB_Exposed = False
  224. Option Explicit
  225. Dim transcriptHasFocus As Integer
  226. Private Sub AddToTranscript(ByVal s As String)
  227.     Dim newtext As String
  228.     Dim i As Integer
  229.     Dim p As Integer
  230.     Dim fixup As Integer
  231.     For i = 1 To Len(s)
  232.         fixup = False
  233.         Select Case Asc(Mid(s, i, 1))
  234.             Case 13
  235.                 If (i < Len(s)) Then
  236.                     If (Mid(s, i + 1, 1) <> Chr(10)) Then
  237.                         fixup = True
  238.                     Else
  239.                         newtext = newtext & Chr(13)
  240.                     End If
  241.                 Else
  242.                     fixup = True
  243.                 End If
  244.             Case 10
  245.                 If (i > 1) Then
  246.                     If (Mid(s, i - 1, 1) <> Chr(13)) Then
  247.                         fixup = True
  248.                     Else
  249.                         newtext = newtext & Chr(10)
  250.                     End If
  251.                 Else
  252.                     fixup = True
  253.                 End If
  254.             Case Else
  255.                 newtext = newtext & Mid(s, i, 1)
  256.         End Select
  257.         If (fixup) Then
  258.             newtext = newtext & Chr(13) & Chr(10)
  259.         End If
  260.     Next
  261.     txtTranscript.Text = txtTranscript.Text & newtext
  262.     txtTranscript.SelStart = Len(txtTranscript.Text) + 1
  263. End Sub
  264. Private Sub Command1_Click()
  265.     Dim i      As Integer
  266.     Dim addr   As String
  267.     Dim lookup As Integer
  268.     Dim c      As String
  269.     txtTranscript.SetFocus
  270.     Command1.Enabled = False
  271.     If (Command1.Caption = "Disconnect") Then
  272.         SocketX.Close
  273.         Command1.Caption = "Connect"
  274.         Command1.Enabled = True
  275.         Exit Sub
  276.     End If
  277.     SocketX.Create
  278.     addr = txtServer.Text
  279.     '
  280.     ' Check to see if name lookup required
  281.     '
  282.     lookup = False
  283.     For i = 1 To Len(addr)
  284.         c = Mid(addr, i, 1)
  285.         If (c <> "." And (c < "0" Or c > "9")) Then
  286.             '
  287.             ' Found a non-numeric character that is not
  288.             ' a dot, need to do a name lookup
  289.             '
  290.             lookup = True
  291.             Exit For
  292.         End If
  293.     Next
  294.     If (lookup) Then
  295.         SocketX.RemoteNameAddrXlate = True
  296.         SocketX.RemoteName = addr
  297.         txtServer.Text = SocketX.RemoteAddress
  298.     Else
  299.         SocketX.RemoteAddress = addr
  300.     End If
  301.     SocketX.RemoteNameAddrXlate = False
  302.     SocketX.RemotePort = CInt(txtPort.Text)
  303.     SocketX.Connect
  304. End Sub
  305. Private Sub Form_KeyPress(keyascii As Integer)
  306.     If (transcriptHasFocus) Then
  307.         If (SocketX.State >= soxConnected) Then
  308.             If (keyascii = 13) Then
  309.                 SocketX.SendBuffer = Chr(13) & Chr(10)
  310.             Else
  311.                 SocketX.SendBuffer = Chr(keyascii)
  312.             End If
  313.             If (chkLocalEcho.Value = 1) Then
  314.                 AddToTranscript CStr(SocketX.SendBuffer)
  315.             End If
  316.             SocketX.Send
  317.         End If
  318.         keyascii = 0
  319.     End If
  320. End Sub
  321. Private Sub Form_Load()
  322.     SocketX.SocketType = soxStream
  323.     SocketX.Blocking = False
  324.     SocketX.EventMask = -1
  325. End Sub
  326. Private Sub SocketX_Done(ByVal LastMethod As SocketXObjLib.MethodsEnum, ByVal ErrorCode As Integer)
  327.     If (LastMethod <> soxReceive And LastMethod <> soxSend) Then
  328.         AddToTranscript "Done(" & LastMethod & "," & ErrorCode & ")" & Chr(13)
  329.     End If
  330. End Sub
  331. Private Sub SocketX_Close(ByVal ErrorCode As Integer)
  332.     AddToTranscript "*** OnClose ***" & Chr(13)
  333.     Command1.Caption = "Connect"
  334.     Command1.Enabled = True
  335. End Sub
  336. Private Sub SocketX_Connect(ByVal ErrorCode As Integer)
  337.     If (ErrorCode = 0) Then
  338.         AddToTranscript "*** OnConnect ***" & Chr(13)
  339.         Command1.Caption = "Disconnect"
  340.     ElseIf (ErrorCode = 10060) Then
  341.         AddToTranscript "Connection timed out"
  342.     Else
  343.         AddToTranscript "Unexpected error " & ErrorCode & Chr(13) & "   " & SocketX.LastErrorString & Chr(13)
  344.     End If
  345.     Command1.Enabled = True
  346. End Sub
  347. Private Sub SocketX_Receive(ByVal ErrorCode As Integer)
  348.     SocketX.Receive
  349.     If (ErrorCode = 0) Then
  350.         AddToTranscript CStr(SocketX.ReceiveBuffer)
  351.     Else
  352.         AddToTranscript "*** Receive Error " & ErrorCode & " ***"
  353.     End If
  354. End Sub
  355. Private Sub SocketX_Send(ByVal ErrorCode As Integer)
  356.     AddToTranscript "*** Send ***" & Chr(13)
  357.     MsgBox "The Send event occured, you can start typing now."
  358. End Sub
  359. Private Sub txtTranscript_GotFocus()
  360.     transcriptHasFocus = True
  361. End Sub
  362. Private Sub txtTranscript_LostFocus()
  363.     transcriptHasFocus = False
  364. End Sub
  365.